<?php
define("CELL_PHONE_LMIN",10);
define("CELL_PHONE_LMAX",12);
class SendOTALinkForm extends Zend_Form{
	public function __construct($options = null)
	{
		parent::__construct($options);

		// get translator
		$registry = Zend_Registry::getInstance();
		$translate = $registry->get('Zend_Translate');
		$agent_config = $registry->get('agent_config');
		// set the form decorator path
		$this->addPrefixPath('Vmg_Form_Decorator', 'Vmg/Form/Decorator', 'decorator');

		// setup validators
		$number_validator = new Zend_Validate_Regex('/^[0-9\r\n]+$/');
		$number_validator->setMessage("This field is only allowed numbers to be keyed in");
		$number_validator->setTranslator($translate);

		// set string length validator
		$phone_validator = new Zend_Validate_StringLength();
		$phone_validator->setMessage("The length of this field must be between %min% and %max%");
		$phone_validator->setMin(CELL_PHONE_LMIN);
		$phone_validator->setMax(CELL_PHONE_LMAX);



		$this->setName("sendotalink");
		$this->setAttrib('id', 'sendotalinkForm');

		$service_code = new Zend_Form_Element_Select('serviceCodeSendotalinkForm');
		$service_code->setRequired(true)
				->setDecorators(array('Composite'))
				->setLabel("Service name");
		$phone = new Zend_Form_Element_Textarea('phoneSendotalinkForm');
		$phone->setDescription("- One number per line <br /> - Use CSV file to import phone numbers to send link")
		->addFilter('StripTags')
		->addFilter('StringTrim')
		->setLabel("Cellphone")
		->setAttrib('cols', 15)
		->setAttrib('rows', 5)
		->setDecorators(array('Composite'))
		->addValidator($number_validator)
		;

		// import
		$fc = Zend_Controller_Front::getInstance();
		$phone_csv = new Zend_Form_Element_File('csvSendotalinkForm');
		$phone_csv->setDecorators(array('Composite'));
		$phone_csv->setLabel("CSV file");
		$phone_csv->addValidator('Size', false, $agent_config->max_csv_file_size);
        $phone_csv->addValidator('Extension', false, 'csv'); // only CSV
		$phone_csv->setDescription("");
		$phone_csv->setDestination($agent_config->upload_tmp_dir);

		$phone_csv_delimiter = new Zend_Form_Element_Text('csvDelimiterSendotalinkForm');
		$phone_csv_delimiter->setDecorators(array('Composite'));
		$phone_csv_delimiter->setLabel("CSV delimiter");
		$phone_csv_delimiter->setValue(",");
		$phone_csv_delimiter->setAttrib('size', 2);
		$phone_csv_delimiter->setDescription("The character will be used to separate two consecutive phone numbers");


		$submit = new Zend_Form_Element_Submit('submit');
		$submit->setAttrib('id', 'submitSendotalinkForm');
		$submit->setValue('Send');
		$submit->setLabel('');
		$submit->setDecorators(array('Composite'));
		$this->setTranslator($translate);
		$this->setAttrib('enctype', 'multipart/form-data');
		$this->addElements(array($service_code, $phone, $phone_csv, $phone_csv_delimiter, $submit));
	}
}
?>